from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template
from html import Link
import os, staticInits

class Header(webapp.RequestHandler):
    'generates header for easy browsing of all pages'

    def get(self):
        'Handles get request, calls renderTemplate().'
        self.renderTemplate()

    
    def renderTemplate(self, addValid = "") :
        'Renders the Template for header.html'
        firstLinks = [Link(url=link.url, title=link.title, target='bottom') for link in staticInits.allLinks]
        lastLink = firstLinks.pop()
        
        #setting up template dictionary
        templateValues = {
            'firstLinks': firstLinks,
            'lastLink': lastLink,
            }

        #telling it to use the template
        path = os.path.join(os.path.dirname(__file__), 'header.html')
        self.response.out.write(template.render(path, templateValues))

application = webapp.WSGIApplication([('/header', Header)], debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()